package com.tenc.exception;

import com.tenc.vo.ApiRest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Alan
 * @since 2021-05-15
 * 异常处理
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 全局异常处理
     * @param e exeption
     * @return Api
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ApiRest fail(Exception e){
        log.error(e.getMessage());
        e.printStackTrace();
        return ApiRest.fail(e.getMessage());
    }



}
